package pe.com.rimac.portal.facturacion.util;

import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;

import pe.com.rimac.portal.facturacion.handler.ListHandler;

/**
 * Clase encargada de facilitar el almacenamiento y acceso a los objetos colocados en la sesi&oacute;n del usuario.
 * 
 * @author Andres Deza Villacorta - Synopsis S.A
 * 
 */
public class SessionHelper
{
	public static final String LIST_HANDLER = "listHandler";
	public static final String INIT_INDEX = "initIndex";
	public static final String VIEW = "view";

	public static int getInitIndex(PortletRequest request)
	{
		return ((Integer) request.getPortletSession().getAttribute(INIT_INDEX)).intValue();
	}

	public static void setInitIndex(PortletRequest request, int initIndex)
	{
		request.getPortletSession().setAttribute(INIT_INDEX, new Integer(initIndex));
	}

	public static void setListHandler(PortletRequest request, ListHandler listHandler)
	{
		request.getPortletSession().setAttribute(LIST_HANDLER, listHandler);
	}

	public static ListHandler getListHandler(PortletRequest request)
	{
		return (ListHandler) request.getPortletSession().getAttribute(LIST_HANDLER);
	}

	public static void setView(PortletRequest request, String view)
	{
		request.getPortletSession().setAttribute(VIEW, view);
	}

	public static String getView(PortletRequest request)
	{
		return (String) request.getPortletSession().getAttribute(VIEW);
	}

	public static void setAttribute(PortletRequest request, String name, Object value)
	{
		request.getPortletSession().setAttribute(name, value);
	}

	public static Object getAttribute(PortletRequest request, String name)
	{
		return request.getPortletSession().getAttribute(name);
	}

	public static void clearSession(PortletRequest request)
	{
		PortletSession session = request.getPortletSession();
		session.removeAttribute(LIST_HANDLER);
		session.removeAttribute(INIT_INDEX);
	}
}